package com.ykq.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ykq.dao.EmpDao;
import com.ykq.entity.Emp;
import com.ykq.service.EmpService;
import com.ykq.util.CommonResult;
import com.ykq.util.TableLayUi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: 145ssm
 * @description:
 * @author: 闫克起2
 * @create: 2021-12-09 11:28
 **/
@Service(value = "empService")
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpDao empDao;

    public List<Emp> findAll() {
        return empDao.selectAll();
    }

    /**
     *
     * @param page 当前页码
     * @param limit 每页显示的条数
     * @param empName  查询条件
     * @param email  查询条件
     * @return
     */
    public TableLayUi findEmpByCondition(int page, int limit, String empName, String email,String did) {
        PageHelper.startPage(page,limit); //开启PageHelper分页
        List<Emp> emps = empDao.selectEmpByCondition(empName, email,did);
        PageInfo<Emp> pageInfo=new PageInfo<Emp>(emps);
        //pageInfo.getTotal:获取的为表中总条数
        //pageInfo.getList():获取的为当前页的记录数据
        return new TableLayUi(0,"",pageInfo.getTotal(),pageInfo.getList());
    }

    public CommonResult update(Emp emp) {
        int row= empDao.updateByPrimaryKeySelective(emp);
        if(row>0){
            return new CommonResult(2000,"修改成功",null);
        }else{
            return new CommonResult(5000,"修改失败",null);
        }
    }
}









